package com.realgodo.site.entity.relation;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import com.realgodo.site.entity.IdEntity;
import com.realgodo.site.entity.space.Space;

@Inheritance(strategy = InheritanceType.JOINED)
@Entity(name = "FriendConfig")
@Table(name = "friend_config")
public class FriendConfig extends IdEntity{
	
	/***/
	private static final long serialVersionUID = -216242649021566041L;
	
	public static final int IS=1;
	public static final int IS_NOT=0;
	private Space onwer;//所有人
	
	private Friend friend;//关系
	
	private int isCare=IS;//动态关注
	
	private int isTop=IS;//首页显示
	
	private String comment;//描述
	
	private Space relater;//关系者
	
	private FriendCatalog catalog;//朋友分组
	
	private Date configDate;
	
	@ManyToOne
	@JoinColumn(name = "catalog_id", referencedColumnName = "id", nullable = true)
	public FriendCatalog getCatalog() {
		return catalog;
	}

	public void setCatalog(FriendCatalog catalog) {
		this.catalog = catalog;
	}
	
	@Transient
	public Space getRelater() {
		if(relater==null){
			relater=getOnwer().getId().equals(friend.getReceiver().getId())?friend.getSender():friend.getReceiver();
		}
		return relater;
	}
	
	@ManyToOne
	@JoinColumn(name = "onwer_id", referencedColumnName = "id", nullable = false)
	public Space getOnwer() {
		return onwer;
	}
	
	public void setOnwer(Space onwer) {
		this.onwer = onwer;
	}

	@ManyToOne
	@JoinColumn(name = "friend_id", referencedColumnName = "id", nullable = false)
	public Friend getFriend() {
		return friend;
	}
	
	public void setFriend(Friend friend) {
		this.friend = friend;
	}

	@Column(name = "is_care")
	public int getIsCare() {
		return isCare;
	}

	public void setIsCare(int isCare) {
		this.isCare = isCare;
	}

	@Column(name = "is_top")
	public int getIsTop() {
		return isTop;
	}

	public void setIsTop(int isTop) {
		this.isTop = isTop;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	@Column(name = "config_date")
	@Temporal(TemporalType.TIMESTAMP)
	public Date getConfigDate() {
		return configDate;
	}

	public void setConfigDate(Date configDate) {
		this.configDate = configDate;
	}

	

	
	
	
	

}
